﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using SQLExecute;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
//using DevExpress.Web.ASPxEditors;


/// <summary>
/// Summary description for school
/// </summary>
public class school
{
    private string _city;
    private string _school_id;
    private string _schoolname;
    private string _address;
    private string _tele;

    public string City
    {
        set { _city = value; }
        get { return _city; }
    }

    public string SchoolID
    {
        set { _school_id = value; }
        get { return _school_id; }
    }
    public string SchoolName
    {
        set { _schoolname = value; }
        get { return _schoolname; }

    }
    public string Address
    {
        set { _address = value; }
        get { return _address; }

    }
    public string Tele
    {
        set { _tele = value; }
        get { return _tele; }

    }
    DataSet ds;


	public school()
	{
		//
		// TODO: Add constructor logic here
		//
	}
   public void Init_Schools(ComboBox cbSchool1, ComboBox cbSchool2, ComboBox cbSchool3, ComboBox cbSchool4)
 
    {
        string sql = "select school_id,schoolname from tbl_schools order by schoolname asc";
        ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, sql);

        cbSchool1.DataSource = ds.Tables[0];                
        cbSchool1.DataTextField = "schoolname";
        cbSchool1.DataValueField = "school_id";
        cbSchool1.DataBind();
        cbSchool1.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool1.SelectedIndex = 0;


        cbSchool2.DataSource = ds.Tables[0];
        cbSchool2.DataTextField = "schoolname";
        cbSchool2.DataValueField = "school_id";
        cbSchool2.DataBind();
        cbSchool2.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool2.SelectedIndex = 0;


        cbSchool3.DataSource = ds.Tables[0];
        cbSchool3.DataTextField = "schoolname";
        cbSchool3.DataValueField = "school_id";
        cbSchool3.DataBind();
        cbSchool3.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool3.SelectedIndex = 0;

        cbSchool4.DataSource = ds.Tables[0];
        cbSchool4.DataTextField = "schoolname";
        cbSchool4.DataValueField = "school_id";
        cbSchool4.DataBind();
        cbSchool4.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool4.SelectedIndex = 0;

    }
 
    public void Init_Schools2(ComboBox cbSchool1, ComboBox cbSchool2, ComboBox cbSchool3, ComboBox cbSchool4)
    {
        string sql = "select * from tbl_schools";
        ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, sql);

        cbSchool1.DataSource = ds.Tables[0];
        cbSchool1.DataTextField = "schoolname";
        cbSchool1.DataValueField = "school_id";
        cbSchool1.DataBind();
        //cbSchool1.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool1.SelectedIndex = 0;


        cbSchool2.DataSource = ds.Tables[0];
        cbSchool2.DataTextField = "schoolname";
        cbSchool2.DataValueField = "school_id";
        cbSchool2.DataBind();
        //cbSchool2.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool2.SelectedIndex = 0;


        cbSchool3.DataSource = ds.Tables[0];
        cbSchool3.DataTextField = "schoolname";
        cbSchool3.DataValueField = "school_id";
        cbSchool3.DataBind();
        //cbSchool3.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool3.SelectedIndex = 0;

        cbSchool4.DataSource = ds.Tables[0];
        cbSchool4.DataTextField = "schoolname";
        cbSchool4.DataValueField = "school_id";
        cbSchool4.DataBind();
        //cbSchool4.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cbSchool4.SelectedIndex = 0;
    }

    public void Insert_School()
    {
        SqlHelper.ExecuteNonQuery(Common.strConnect, "Insert_School", new object[] { this._school_id,this._city, this._schoolname, this._address, this._tele });
    }
    public DataSet Get_List_School()
    {
        string sql = "select * from tbl_schools order by schoolname asc";

        DataSet ds=SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, sql);
        return ds;
    }
    public void Get_All_Schools(DropDownList cb)
    {

        string strSQL = "select * from tbl_schools";
        ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, strSQL);
        cb.DataSource = ds;
        cb.DataTextField = "school_id";
        cb.DataValueField = "school_id";
        cb.DataBind();
        cb.Items.Insert(0, new ListItem("CHOOSE ONE", "CHOOSE ONE"));
        cb.SelectedIndex = 0;
    }
    public DataSet Get_List_School(string city_id)
    {
        string sql = "select * from tbl_schools where city_id='"+city_id+"'" ;

        DataSet ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, sql);
        return ds;
    }
    public void Update_School(string oldid,string newid, string name)
    { string sql;
        if (oldid!=newid)
            sql="update tbl_schools set school_id='"+newid+"',schoolname=N'"+name+"' where school_id='"+oldid+"'";
        else
            sql = "update tbl_schools set schoolname=N'" + name + "' where school_id='" + oldid + "'";

        SqlHelper.ExecuteNonQuery(Common.strConnect, CommandType.Text, sql);
    }

    public bool School_Exists()
    {
        string sql = "select * from tbl_schools where school_id=N'" + _school_id + "'";
        ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, sql);
        if (ds.Tables[0].Rows.Count > 0)
            return true;
        else return false;       
    }
    
}
